﻿using System;
using System.Collections.Generic;
using System.Text;
using Company.BLL.WS.GC;
using System.Data;
using System.Data.SqlClient;

namespace Company.BLL.GC
{
    public class NhomSanPham : NhomSanBase
    {
        public static DataSet WS_GetDanhSachDaDangKy(string maHaiQuan, string maDoanhNghiep)
        {
            GCService service = new GCService();
            return service.LoaiSanPham_GetDanhSach(maHaiQuan, maDoanhNghiep);
        }

        public static bool UpdateRegistedToDatabase(string maHaiQuan, string maDoanhNghiep,SqlTransaction transaction)
        {
            // Lấy danh sách từ WEB SERVICE.
            DataSet ds = WS_GetDanhSachDaDangKy(maHaiQuan, maDoanhNghiep);

            // Cập nhật vào CSDL.
            NhomSanPhamCollection collection = new NhomSanPhamCollection();
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                NhomSanPham nhomsp = new NhomSanPham();
                nhomsp.SoHopDong = row["SoHopDong"].ToString();
                nhomsp.MaHaiQuan = row["MaHaiQuan"].ToString();
                nhomsp.MaDoanhNghiep = row["MaDoanhNghiep"].ToString();
                nhomsp.NgayKy = Convert.ToDateTime(row["NgayKy"]);
                nhomsp.Ma = row["Ma"].ToString().Substring(1);
                nhomsp.Ten = Company.BLL.DuLieuChuan.NhomSanPham.getTenSanPham(nhomsp.Ma);                            
                nhomsp.SoLuongDangKy = Convert.ToDecimal(row["SoLuong"]);
                nhomsp.TriGia= Convert.ToDecimal(row["Gia"]);
                nhomsp.InsertUpdateTransaction(transaction);
            }
            return true;
        }
    }
}
